"""
File: member_add_page.py
Author: ershixiong
Date: 2023/11/23
describe:

"""
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from project202311_wework.wework.wework_po.page_object.base_page import BasePage
from project202311_wework.wework.wework_po.utiles.log_utils import logger


class MemberAddPage(BasePage):
    __INPUT_USERNAME = (By.NAME, 'username')
    __INPUT_ACCOUNT = (By.NAME, 'acctid')
    __INPUT_MOBILE = (By.NAME, 'mobile')
    __BTN_CONFIRM = (By.XPATH, '//*[text()="保存"]')

    def add_member(self,username,account,mobile):
        logger.info('新增成员页面：新增成员')

        logger.debug(f'姓名:{username},账号:{account},手机:{mobile}')
        # 添加等待新增页面的元素，确认页面刷新出来再执行输入操作
        WebDriverWait(self.driver,10).until(
            expected_conditions.visibility_of_element_located(self.__INPUT_USERNAME)
        )
        # self.wait_element_until_visible(self.__INPUT_USERNAME)

        self.do_send(username, *self.__INPUT_USERNAME)
        self.do_send(account, *self.__INPUT_ACCOUNT)
        self.do_send(mobile, *self.__INPUT_MOBILE)

        self.do_click(*self.__BTN_CONFIRM)
        from project202311_wework.wework.wework_po.page_object.contacts_page import ContractsPage
        return ContractsPage(self.driver)
